package ACWing._789_第k个数;

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main2_heap {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        // 最大堆（堆顶最大）
        PriorityQueue<Integer> queue = new PriorityQueue<>(((o1, o2) -> o2-o1));
        for (int t : a) {
            if(queue.size()<k)
                queue.add(t);
            else{
                // 如果t小于堆顶则,堆顶出队，t入队
                if(!queue.isEmpty()&&t < queue.peek()){
                    queue.poll();
                    queue.add(t);
                }
            }
        }
        System.out.println(queue.poll());
        scanner.close();
    }
}
